package constant.milk.cashbook.asset;

import constant.milk.cashbook.R;
import constant.milk.cashbook.SuperActivity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MemoActivity extends SuperActivity
{
	public static final String MEMO_DATA = "MEMO_DATA";
	
	private EditText memoEditText;
	private TextView memoTextView;
	
	private Button checkButton;
	
	private InputMethodManager imm;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.memo_activity);
		
		setTitle("내용");
		
		setGoneTipButton();
		
		imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		memoEditText = (EditText) findViewById(R.id.memoEditText);
		memoTextView = (TextView) findViewById(R.id.memoEditView);
		
		checkButton = (Button) findViewById(R.id.checkButton);
	}

	@Override
	protected void setOnClick()
	{
		memoTextView.setOnTouchListener(new OnTouchListener()
		{
			@Override
			public boolean onTouch(View v, MotionEvent event)
			{
				imm.hideSoftInputFromWindow(memoEditText.getWindowToken(), 0);
				memoEditText.clearFocus();
				
				return false;
			}
		});
		
		checkButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent();
				intent.putExtra(MEMO_DATA, memoEditText.getText().toString());
				setResult(Activity.RESULT_OK, intent);
				finish();
			}
		});
	}

	@Override
	protected void setData()
	{
		Intent intent = getIntent();
		String memo = intent.getStringExtra(MEMO_DATA);
		
		memoEditText.setText(memo);
		
		memoEditText.requestFocus();
	}

	@Override
	protected void tipButton()
	{
	}

}
